package cn.kgc.filter;


import javax.servlet.*;
import java.io.IOException;

public class CharEncodingFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharEncodingFilter 初始化方法 ... ...");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("进入了 doFilter() 方法 ... ...");
        //所有中文进行统一编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        chain.doFilter(request, response);
    }

    public void destroy() {
        System.out.println("CharEncodingFilter 销毁方法 ... ...");
    }
}
